// pages/home_center/common_panel/components/Enum/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    value: String,
    dpCode: String,
    dpName: String,
    range: Array,
  },

  /**
   * 组件的初始数据
   */
  data: {
    range: [],
    subValue: ''
  },

  lifetimes: {
    attached: function () {
      const {
        range,
        value
      } = this.properties
      this.setData({
        subValue: value
      })
      this.setData({
        range
      })
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange: function (event) {
      const {
        dpCode
      } = this.properties
      const {
        dataset: {
          value
        }
      } = event.currentTarget
      console.log('range', this.data.range)
      this.setData({
        subValue: this.data.range.length > 1 ? value : this.data.subValue === 'default' ? value : 'default'
      })
      console.log(this.data.subValue)
      this.triggerEvent('sendDp', {
        dpCode,
        value
      })
    }
  }
})